
/**
 * 函数柯里化
 * @param {*} fn 
 * @returns 
 */
var currying = function (fn) {
    var args = []

    return function () {
        if(arguments.length === 0) {
            return fn.apply(this,args)
        }else {
            [].push.apply(args,arguments)
            // console.log(arguments.callee());

        }
    }
}

var compute = (() => {
    var money = 0
    return function () {
        for (let i = 0; i < arguments.length; i++) {
            money = money + arguments[i]
        }
        return money
    }
})()

// 未柯里化的函数
// console.log(compute(100));
// console.log(compute(200));
// console.log(compute(300));

var cost = currying(compute) // 已完成柯里化

cost(100)
cost(200)
cost(300)

// console.log(cost());



